/**
 * 
 */
package com.depot.auth.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.depot.auth.dao.UserRoleDao;
import com.depot.domains.UserRole;
import com.opensymphony.xwork2.ModelDriven;
import com.soar.BaseActionSupport;
import com.soar.context.Environment;

/**
 * 
 * @author Gravey Quen
 * @version $Revision$ - $Author$ at $Date$
 * @description com.itaskstar.auth.web.UserRoleAction
 */
public class UserRoleAction extends BaseActionSupport implements ModelDriven<UserRole>
{
	private static final long serialVersionUID = 1L;

	public UserRole domain = new UserRole();

	public HashMap<String, String> userrole = new HashMap<String, String>();

	public List<HashMap<String, String>> users = new ArrayList<HashMap<String, String>>();

	/**
	 * 用户角色列表
	 * 
	 * @param env
	 * @param domain
	 * @param action
	 * @return
	 * @throws Exception
	 */
	public String execute(Environment env) throws Exception
	{
		this.sysPageList = UserRoleDao.select(env, domain);
		this.users = UserRoleDao.users(env, domain);
		return "user_role";
	}

	/**
	 * 保存用户角色
	 * 
	 * @param env
	 * @return
	 * @throws Exception
	 */
	public String doSave(Environment env) throws Exception
	{
		String result = UserRoleDao.doSave(env, domain);
		if ("1".equals(result))
		{
			this.setMessage("操作成功！", env, true);
		}
		else
		{
			this.setMessage("操作失败，请重试！", env, false);
		}
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
	 */
	public UserRole getModel()
	{
		return this.domain;
	}
}